﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserBackGround_CheckInfo : System.Web.UI.Page
{
    Operation operation = new Operation(); //业务类对象
    static string userid;
    static string Em;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["userid"] == null)
                Response.Write("<script language=javascript>alert('会话失效，请重新登录！');</script>");
            else
            {
                userid = Session["userid"].ToString().Trim();
                BuildData(userid);
                msg.Visible = false;
            }
        }
    }
    /// <summary>
    /// 初始化页面
    /// </summary>
    
    private void BuildData(string uid)
    {
        DataSet ds = operation.SelectUserInfo(uid);
        type.Text = ds.Tables[0].Rows[0][3].ToString();
        name.Text = ds.Tables[0].Rows[0][1].ToString();
        //password = ds.Tables[0].Rows[0][2];

        tel.Text = ds.Tables[0].Rows[0][5].ToString();
        email.Text = ds.Tables[0].Rows[0][4].ToString();
        qq.Text = ds.Tables[0].Rows[0][6].ToString();
        msn.Text = ds.Tables[0].Rows[0][7].ToString();
        regtime.Text = ds.Tables[0].Rows[0][8].ToString();
        tbComname.Text = ds.Tables[0].Rows[0][10].ToString();
        tbAddress.Text = ds.Tables[0].Rows[0][11].ToString();
        tbOrgDetail.Text = ds.Tables[0].Rows[0][12].ToString();
        if (type.Text.Equals("企业用户"))
        {
            lbAddress.Text = "企业地址:";
            lbComname.Text = "企业名称:";
            lbOrgDetail.Text = "企业简介:";
        }
        else if (type.Text.Equals("科研机构"))
        {
            lbAddress.Text = "机构地址:";
            lbComname.Text = "机构名称:";
            lbOrgDetail.Text = "机构简介:";
        }
        else
        {
            lbAddress.Text = "住址:";
            lbComname.Visible = false;
            tbComname.Visible = false;
            lbOrgDetail.Text = "个人简介:";
        }
        Em = email.Text;
    }

    protected void Save_Click(object sender, EventArgs e)
    {
        if (Em==email.Text||operation.ValidateEmail(email.Text.Trim()).Tables[0].Rows.Count <= 0)
        {
            operation.UpdateUserInfo(name.Text.Trim(), type.Text.Trim(),
                email.Text.Trim(), tel.Text.Trim(), qq.Text.Trim(), msn.Text.Trim(),this.tbComname.Text.Trim(),
                this.tbAddress.Text.Trim(),this.tbOrgDetail.Text.Trim(),userid);
            msg.Visible = false;
            Em = email.Text;
            Response.Write("<script>alert('已保存!');</script>");
        }
        else
        {
            msg.Visible = true;
        }
    }
}